/**
 * @Copyright 2012, Founder Mobile Media Technology（Chongqing） Co., Ltd L.P. All
 *            rights reserved. The information contained herein is confidential
 *            and proprietary to Founder Mobile Media Technology（Chongqing） Co.,
 *            Ltd, and considered a trade secret as defined under civil and
 *            criminal statutes. Founder Mobile Media Technology（Chongqing） Co.,
 *            Ltd shall pursue its civil and criminal remedies in the event of
 *            unauthorized use or misappropriation of its trade secrets. Use of
 *            this information by anyone other than authorized employees of
 *            Founder Mobile Media Technology（Chongqing） Co., Ltd is granted
 *            only under a written non-disclosure agreement, expressly
 *            prescribing the scope and manner of such use.
 */
package com.g2room.quartz;

import java.text.SimpleDateFormat;
import java.util.Calendar;

import org.quartz.DisallowConcurrentExecution;
import org.quartz.Job;
import org.quartz.JobDataMap;
import org.quartz.JobExecutionContext;
import org.quartz.JobExecutionException;
import org.quartz.PersistJobDataAfterExecution;

/**
 * 任务执行具体类
 * 
 * @createTime: Apr 18, 2013 9:32:04 PM
 * @author: <a href="mailto:gaoxg@FOUNDER.COM.CN">Xuguo Gao</a>
 * @version: 0.1
 * @lastVersion: 0.1
 * @updateTime:
 * @updateAuthor: <a href="mailto:gaoxg@FOUNDER.COM.CN">Xuguo Gao</a>
 * @changesSum:
 * 
 */
// JobDataMap的持久化
@PersistJobDataAfterExecution
// 保证多个任务间不会同时执行
@DisallowConcurrentExecution
public class Jobs implements Job {
	private static int count = 0;
	private int myCount = 0;  
	private static int myStaticCount = 0;  
	public static final String JOB_DATA_MAP_KEY = "key1";  
	/**
	 * 
	 * 
	 * @auther <a href="mailto:gaoxg@FOUNDER.COM.CN">Gao Xuguo</a> Apr 18, 2013
	 *         9:32:30 PM
	 */
	public void execute(JobExecutionContext context)
			throws JobExecutionException {
		System.out.println("------------"+context.getJobDetail().getKey());
	        System.out.println(" ***************************************** ");
	        SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy年MM月dd日 HH时mm分ss秒");  
	        System.out.println(" 第" + count + "次任务 ");
	        String jobName = context.getJobDetail().getKey().getName();
	        System.out.println("任务Key:" + jobName + " 正在执行，执行时间: " + dateFormat.format(Calendar.getInstance().getTime()));
	        count++;
//	        JobDataMap properties = context.getJobDetail().getJobDataMap();
	        
	        JobDataMap data = context.getJobDetail().getJobDataMap();  
	        int jobDataMapInt = data.getInt(JOB_DATA_MAP_KEY);  
	        // 这里注释的内容用于理解DisallowConcurrentExecution这个注解  
	        //if (jobDataMapInt == 11) {  
	        //  try {  
	        //      Thread.sleep(11000);
	        //  } catch (InterruptedException e) {  
	        //      e.printStackTrace();  
	        //  }  
	        //}  
	        System.out.println("***private成员变量为:" + myCount + ",static成员变量为:" + myStaticCount + ",JobDataMap保存的变量为:" + jobDataMapInt);  
	        myCount++;
	        myStaticCount++;
	        jobDataMapInt++;
	        data.put(JOB_DATA_MAP_KEY, jobDataMapInt);

	        System.out.println("上一次执行时间: " + context.getPreviousFireTime());// 上次执行时间  
	        System.out.println("当前的执行时间: " + context.getFireTime());// 本次执行时间  
	        System.out.println("下一次执行时间: " + context.getNextFireTime());// 下一次执行时间  
	}
}
